﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NBusiness.Data.Providers.SqlServer.Query;

namespace NBusiness.Query.Testing
{
    [TestClass]
    class TableTests
    {
        [TestMethod]
        public void OrderByTest1()
        {
            SqlTable table = new SqlTable("T");
            SqlColumn c = new SqlColumn("C", table);

            ISelect select = table.OrderBy(SortOrder.Asc, c);

            string expected = "SELECT * FROM [T] AS [A] ORDER BY [A].[C] ASC";
            string actual = select.ToSql();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void TestColumn()
        {
            ITable table = new SqlTable("T");
            IColumn c = table.Column("C");

            string expected = "[A].[C]";
            string actual = c.ToSql();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void TestAlias()
        {
            ITable table = new SqlTable("T").As("Blah");

            string expected = "[T] AS [Blah]";
            string actual = table.ToSql();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void TestToString()
        {
            ITable table = new SqlTable("T");

            string expected = "[T]";
            string actual = table.ToString();

            Assert.AreEqual(expected, actual);
        }
    }
}
